package com.itheima.nacos.comtroller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Service1Controller {

    @Autowired
    ConfigurableApplicationContext applicationContext;

    @Value("${common.name}")
    private String config1;


    @GetMapping("/getconfig1")
    public String getConfig1(){
//        return "获取的配置为: " + config1;
        return applicationContext.getEnvironment().getProperty("common.name");
    }


    @GetMapping("/getconfig")
    public String getConfig(){
        String configStr = null;
        String name = applicationContext.getEnvironment().getProperty("common.name");
        String age = applicationContext.getEnvironment().getProperty("common.age");
        String address = applicationContext.getEnvironment().getProperty("common.address");
        String birthday = applicationContext.getEnvironment().getProperty("common.birthday");
        String funllname = applicationContext.getEnvironment().getProperty("common.fullname");
        String sex = applicationContext.getEnvironment().getProperty("common.sex");
        configStr = "name：" + name + "；age：" + age + "；address：" + address + "；birthday：" + birthday + "；funllname：" + funllname + "；sex：" + sex;
        return configStr;
    }
}
